package com.leet.competition;

import java.util.*;

public class NumberOfWeak {
    public int numberOfWeakCharacters(int[][] properties) {
        Arrays.sort(properties, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if(o1[0]!=o2[0]) return o2[0]-o1[0];
                return o1[1]-o2[1];
            }
        });
        int cnt = 0;
        int max_n = -1;
        for(int i = 0; i <properties.length;i++){
            if(max_n > properties[i][1]){
                cnt++;
            }
            max_n = Math.max(max_n,properties[i][1]);
        }
        return cnt;
    }
}
